package com.briup.server.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.briup.common.response.Result;
import com.briup.server.domain.bean.DeviceType;
import com.briup.server.domain.dto.ConditionQueryDTO;
import com.briup.server.service.DeviceTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "设备分类管理模块")
@RestController
@RequestMapping("/device/type")
@RequiredArgsConstructor
public class DeviceTypeController {

    private final DeviceTypeService service;

    @Operation(summary = "分页条件查询设备分类数据")
    @GetMapping("/page")
    public Result<Page<DeviceType>> pageQuery(ConditionQueryDTO queryDTO) {
        Page<DeviceType> page = service.pageQuery(queryDTO);
        return Result.success(page)
                .apply("分页查询成功");
    }

    @Operation(summary = "获取设备分类列表（用于新增或修改设备信息时分配设备类型）")
    @GetMapping("/list")
    public Result<List<DeviceType>> list() {
        List<DeviceType> list = service.list();
        return Result.success(list)
                .apply("获取成功");
    }

    @Operation(summary = "修改设备分类")
    @PutMapping
    public Result<?> update(@RequestBody @Valid DeviceType deviceType) {
        service.saveOrUpdate(deviceType);
        return Result.success();
    }

    @Operation(summary = "新增设备分类")
    @PostMapping
    public Result<?> save(@RequestBody @Valid DeviceType deviceType) {
        service.saveOrUpdate(deviceType);
        return Result.success();
    }

    @Operation(summary = "删除设备分类（单删、批量删除）")
    @DeleteMapping
    public Result<?> delete(@RequestBody List<String> ids) {
        service.removeByIds(ids);
        return Result.success();
    }
}
